<template>
	<view class="container">
		<view v-if="!giveGoodsInfo.image">
			<image :src="url+'/static/imgs/give.png'" class="give_class"></image>
			<view class="give_content">
				<view class="give_title row">
					<image :src="storeInfo.store_pic" mode="aspectFill"></image>
					<view>{{storeInfo.store_name}}</view>
				</view>
				<view class="givelist">
					<text>送好友一道你最喜欢的菜品。</text>
					<text>好友到本店</text>
					<text>消费任意菜品即可免费享用您送出的菜品。</text>
				</view>
				<image class="give_img" :src="url+'/static/imgs/choose-goods.png'" mode="aspectFill" @click="toChooseGoods"></image>
			</view>
		</view>
		<view v-else>
			<image :src="url+'/static/imgs/give1.png'" class="give_class give_class_hover"></image>
			<view class="give_content give_content_hover">
				<view class="give_title give_title_hover row">
					<image :src="storeInfo.store_pic" mode="aspectFill"></image>
					<view>{{storeInfo.store_name}}</view>
				</view>
				<text class="give_msg">我送你一份{{giveGoodsInfo.name}}，喜欢就来领取吧！</text>
				<image class="give_img" :src="giveGoodsInfo.image" mode="aspectFill" @click="toChooseGoods"></image>
			</view>
			<view class="row friendsicon">
				<button open-type="share">
					<image :src="url+'/static/imgs/one.png'"></image>
					<text>送单个好友</text>
				</button>
				<button @click="onShareTap">
					<image :src="url+'/static/imgs/two.png'"></image>
					<text>送多个好友</text>
				</button>
			</view>
		</view>
	</view>
</template>

<script>
	var app = getApp();
	import http from "../../../../common/js/request.js";
	import common from "../../../../common/js/function.js";
	export default {
		data() {
			return {
				url: app.globalData.baseImgUrl,
				store_id: app.globalData.storeId,
				storeInfo: [],
				giveGoodsInfo: [],
				userInfo: [], //用户信息
			}
		},
		onShow() {
			var that = this;
			common.verifyAuth(() => {
				that.getStoreInfo();
				that.getUserInfo();
				//	console.log('app.globalData.giveGoodsInfo', app.globalData.giveGoodsInfo);
				that.giveGoodsInfo = app.globalData.giveGoodsInfo || [];
			}, true);
		},

		onShareAppMessage() {
			var that = this;
			var pages = getCurrentPages() //获取加载的页面
			var currentPage = pages[pages.length - 1] //获取当前页面的对象
			var url = currentPage.route //当前页面url
			var options = currentPage.options //如果要获取url中所带的参数可以查看options
			var param = '';
			for (var key in options) {
				param += '&' + key + '=' + options[key];
			}
			var timestamp = (new Date()).getTime();
			var path = '/pages/store/home/home' + param;
			path = path + '?mode=wx_share&store_id=' + that.store_id + '&send_id=' + that.userInfo.id + '&goods_id=' + that.giveGoodsInfo
				.id+'&share_id='+that.userInfo.id+""+timestamp;
			console.log(path);
			return {
				path
			}
		},
		methods: {
			//用户信息
			getUserInfo() {
				var that = this;
				http.post('/api/v1/member/member_info', {}, res => {
					that.userInfo = res.datas;
				});
			},
			//店铺详情
			getStoreInfo() {
				var that = this;
				http.post('/api/v1/store/store_detail', {
					store_id: that.store_id
				}, res => {
					that.storeInfo = res.datas;
				});
			},
			//跳转至选择菜品
			toChooseGoods() {
				var that = this;
				uni.navigateTo({
					url: '/pages/store/give/category/category'
				});
			},
			//分享好友
			onShareTap() {
				uni.navigateTo({
					url: '../share/share'
				})
			}
		}
	}
</script>

<style>
	.give_class {
		width: 689rpx;
		height: 981rpx;
		display: block;
		margin: 62rpx auto !important;
		padding: 0 27rpx;
	}

	.give_class_hover {
		height: 776rpx !important;
	}

	.give_content {
		width: 689rpx;
		height: 981rpx;
		position: absolute;
		top: 62rpx;
		left: 50%;
		margin-left: -345rpx;
	}

	.give_content_hover {
		height: 776rpx !important;
	}

	.give_title {
		height: 131rpx;
		line-height: 131rpx;
		margin: 35rpx;
	}

	.give_title_hover {
		margin: 15rpx 35rpx !important;
	}

	.give_title image {
		width: 131rpx;
		height: 131rpx;
		border-radius: 50%;
	}

	.give_title view {
		font-size: 30rpx;
		color: #FFFFFF;
		margin-left: 20rpx;
	}

	.givelist text {
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: rgba(255, 157, 17, 1);
		line-height: 60rpx;
		display: block;
	}

	.givelist {
		margin-top: 98rpx;
		margin-left: 60rpx;
	}

	.give_img {
		width: 380rpx;
		height: 300rpx;
		display: block;
		margin: 33rpx auto 0;
		border-radius: 10rpx;
	}

	.give_msg {
		font-size: 30rpx;
		color: #FF9D11;
		width: 520rpx;
		margin: 70rpx auto 0rpx;
		text-align: center;
		display: block;
	}

	.friendsicon>view {
		width: 50%;
		text-align: center;
	}

	.friendsicon image {
		width: 117rpx;
		height: 117rpx;
		display: block;
		margin: 0 auto;
	}

	.friendsicon text {
		font-size: 28rpx;
		color: #333;
	}
</style>
